Skip to content

refactor(vr): prefer globals::game::isVR#113

Merged
alandtse merged 4 commits into
devfrom
copilot/refactor-prefer-cached-globals-isvr
Jun 7, 2026
Merged

refactor(vr): prefer globals::game::isVR#113
alandtse merged 4 commits into
devfrom
copilot/refactor-prefer-cached-globals-isvr

Conversation

Copilot AI commented Jun 6, 2026

Copy link
Copy Markdown

This refactor applies the VR-divergence guideline by replacing direct REL::Module::IsVR() runtime checks with the cached globals::game::isVR where call timing is safe. Remaining raw module checks are intentionally limited to init/early-init and header initialization contexts.

  • Scope: timing-safe runtime callsites

    • Swapped direct module checks to globals::game::isVR across major runtime paths in src/ (deferred rendering, hooks, shader cache runtime logic, UI/game utils, feature runtime code including LLF/SSGI/VR/upscaling).
    • Goal: use one cached runtime source instead of repeated module queries during normal execution.
  • Intentional raw-check exceptions

    • Kept raw REL::Module::IsVR() at the cache population site in Globals.cpp.
    • Kept raw checks in early plugin load path (XSEPlugin.cpp) where globals::game::isVR is not yet initialized.
    • Kept raw checks in header/default-init/macro/static-init contexts (Globals.h, ShaderCache.h, Utils/Game.h, ScreenSpaceGI.h, LightLimitFix.h, Menu.h) where initialization order/timing can precede ReInit.
    • Added brief one-line reasons at non-obvious retained sites.
  • Net effect

    • Runtime VR branching is now predominantly routed through globals::game::isVR, with raw calls constrained to legitimate init-order exceptions.
// Before
if (REL::Module::IsVR()) {
    // VR path
}

// After (timing-safe runtime path)
if (globals::game::isVR) {
    // VR path
}

Copilot AI changed the title [WIP] Refactor to prefer cached globals::game::isVR over REL::Module::IsVR() Refactor VR runtime checks to prefer cached globals::game::isVR Jun 6, 2026
Copilot AI requested a review from alandtse June 6, 2026 19:22
Aligns the inline comment spacing and macro line-continuation
backslashes added by the globals::game::isVR refactor so the
pre-commit.ci clang-format hook passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alandtse alandtse changed the title Refactor VR runtime checks to prefer cached globals::game::isVR refactor(vr): prefer cached globals::game::isVR over REL::Module::IsVR() Jun 6, 2026
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

No actionable suggestions for changed features.

@alandtse alandtse marked this pull request as ready for review June 6, 2026 23:59
Copilot AI review requested due to automatic review settings June 6, 2026 23:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors VR runtime branching across the rendering/plugin codebase to prefer the cached globals::game::isVR flag instead of repeated REL::Module::IsVR() checks, while preserving direct module checks in early-init / static-init contexts where globals::game::isVR may not be initialized yet.

Changes:

  • Replaced many runtime REL::Module::IsVR() checks with globals::game::isVR across hooks, rendering paths, shader compilation/defines, UI helpers, and feature code.
  • Constrained remaining direct module checks to known init-order-sensitive sites (plugin early load, header/static initialization, and the cache population site) and annotated those exceptions.
  • Standardized VR define insertion and VR/flat branching to route through the cached global where timing is safe.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/XSEPlugin.cpp Keeps direct VR check for pre-ReInit gating, uses cached globals::game::isVR after globals::ReInit() for runtime DLL gating.
src/Utils/UI.cpp Routes VR-specific input/display logic through globals::game::isVR.
src/Utils/Game.h Documents why macros retain direct module VR checks (macro may be used pre-ReInit).
src/Utils/Game.cpp Uses cached VR flag for camera/eye and TAA runtime branching.
src/Utils/D3D.h Switches VR-aware render target count helpers to cached VR flag.
src/Utils/D3D.cpp Uses cached VR flag when adding shader compile macros.
src/TruePBR.cpp Uses cached VR flag for VR-vs-flat allocation sizing.
src/ShaderCache.h Annotates and retains direct module check for static initialization safety.
src/ShaderCache.cpp Uses cached VR flag for SIE signature/define logic and shader compile defines.
src/Menu/HomePageRenderer.cpp Uses cached VR flag to suppress first-time setup in VR.
src/Menu.h Annotates and retains direct module check for ctor-time default initialization.
src/Hooks.cpp Uses cached VR flag for install-time gating and VR/flat patch selection.
src/Globals.h Annotates why header helpers keep direct module checks to avoid init-order coupling.
src/Globals.cpp Keeps module check as the source-of-truth to populate globals::game::isVR; uses cached flag downstream.
src/Features/VRStereoOptimizations.cpp Uses cached VR flag to early-out VR-only resource/setup paths.
src/Features/VR/StereoBlend.cpp Uses cached VR flag for VR-only stereo blend execution gating.
src/Features/VR.h Uses cached VR flag for VR feature readiness predicate.
src/Features/Upscaling/PerfMode/MenuBridge.cpp Uses cached VR flag for VR-only RT thunk installation.
src/Features/Upscaling/DX12SwapChain.cpp Uses cached VR flag for VR-specific swap chain behavior.
src/Features/Skylighting.cpp Uses cached VR flag for VR-specific hook installation.
src/Features/ScreenSpaceGI.h Uses cached VR flag for VR warning text; retains module checks for ctor defaults.
src/Features/ScreenSpaceGI.cpp Uses cached VR flag for VR-only shader variants, stereo iteration counts, and stereo sync pass gating.
src/Features/ScreenshotFeature.cpp Uses cached VR flag for VR-only default preset seeding.
src/Features/RemoteControl/DevBenchBridge.cpp Uses cached VR flag for VR compatibility enforcement and telemetry payload.
src/Features/LightLimitFix/ShadowCasterManager.cpp Uses cached VR flag for VR/flat calling conventions and runtime data access branching.
src/Features/LightLimitFix.h Annotates and retains direct module check for ctor-time default eye count.
src/Features/LightLimitFix.cpp Uses cached VR flag for VR-specific sizing/defines and render-size branching.
src/Features/GrassCollision.cpp Uses cached VR flag for VR per-frame buffer selection.
src/FeatureIssues.cpp Uses cached VR flag for VR feature INI gating.
src/Feature.cpp Uses cached VR flag to choose the VR-vs-flat feature list.
src/Deferred.h Uses cached VR flag for VR-vs-flat hook installation decisions.
src/Deferred.cpp Uses cached VR flag for VR buffer binding and shader define selection.

@alandtse alandtse changed the title refactor(vr): prefer cached globals::game::isVR over REL::Module::IsVR() refactor(vr): prefer globals::game::isVR Jun 7, 2026
@alandtse alandtse merged commit 3b904eb into dev Jun 7, 2026
27 of 28 checks passed
@alandtse alandtse deleted the copilot/refactor-prefer-cached-globals-isvr branch June 7, 2026 00:20
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: prefer cached globals::game::isVR over REL::Module::IsVR() where possible

3 participants